package com.last1mile.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.last1mile.commons.PaymentStatusEnum;
import com.last1mile.commons.TradeStatusEnum;
import com.last1mile.dao.interfaces.TradeDao;
import com.last1mile.model.Trade;
import com.last1mile.pojo.TradeDO;
import com.last1mile.service.TradeService;

@Component("tradeServiceImpl")
public class TradeServiceImpl implements TradeService {

    @Autowired
    @Qualifier("tradeDao")
    private TradeDao tradeDao;

    @Override
    public Integer createTrade(Trade trade) {
        if (trade != null) {
            TradeDO tradeDo = new TradeDO();
            tradeDo.setMerId(trade.getMerId());
            tradeDo.setMerServeId(trade.getMerServeId());
            tradeDo.setPerId(trade.getPerId());
            tradeDo.setTradeAmt(trade.getTradeAmt());
            tradeDo.setTradeCuy(trade.getTradeCuy().getValue());
            tradeDo.setPaymentStatus(PaymentStatusEnum.INIT.getValue());
            tradeDo.setTradeStatus(TradeStatusEnum.INIT.getValue());
            tradeDo.setNote(trade.getNote());

            return this.tradeDao.inserTrade(tradeDo);
        } else {
            return null;
        }
    }

    @Override
    public List<TradeDO> queryTradeByMer(Integer merId) {
        return this.tradeDao.queryTradeByMerId(merId);
    }

    @Override
    public List<TradeDO> queryTradeByPer(Integer perId) {
        return this.tradeDao.queryTradeByPerId(perId);
    }

}
